/**
 * *********************** ******* ***********************************
 *
 *  
 * 
 *  
 * *******************************************************************
 */

package com.arges.web.common;

import java.lang.reflect.Type;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * 用于生成 Gson对象，从而可以进行 对象 和 json字符串之间的转化
 *
 * 
 * @version Ver 3.0
 * @since Ver 3.0
 * @Date 2012-9-12
 *
 */
public class GsonUtils
{

	public static Gson getGson()
	{
		GsonBuilder gsonBuilder = new GsonBuilder();
		gsonBuilder.excludeFieldsWithoutExposeAnnotation();
		return gsonBuilder.create();
	}

	public static Gson getGsons()
	{
		Gson gson = new Gson();
		return gson;
	}

	public static <T> Map<String, T> getMap(String map, Type type)
	{
		Gson gson = new Gson();
		Map<String, T> result = gson.fromJson(map, type);
		return result;
	}

	/**
	 * 实体类转换成json字符串
	 * 
	 * @param object
	 * @return
	 */
	public static String objectToJson(Object object)
	{
		Gson gson = new Gson();
		String json = gson.toJson(object);
		return json;
	}

	public static <T> T stringToObject(String json, Class<T> clazz)
	{
		Gson gson = new Gson();
		T t = gson.fromJson(json, clazz);
		return t;
	}
}
